package com.ruoyi.stuclient.controller;

import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.core.context.ThirdSessionHolder;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.stuclient.domain.vo.EwcHomeworkAnalysisVo;
import com.ruoyi.stuclient.domain.vo.EwcHomeworkVo;
import com.ruoyi.stuclient.service.IEwcHomeworkService;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotBlank;
import java.util.List;

/**
 * 课后作业Controller
 * 
 * @author lcj
 * @date 2025-02-28
 */
@Validated
@RestController
@RequestMapping("/api/homework")
public class EwcHomeworkController extends BaseController
{
    @Autowired
    private IEwcHomeworkService ewcHomeworkService;

    /**
     * 查询课后作业列表
     */
    @Operation(summary = "学生端我的页面查询课后作业列表")
    @GetMapping("/getHomeworkListInfo")
    public AjaxResult getHomeworkListInfo(String homeworkType,String homeworkTitle)
    {
        List<EwcHomeworkVo> listHomework = ewcHomeworkService.getHomeworkListInfo(ThirdSessionHolder.getThirdSession().getId(),homeworkType,homeworkTitle);
        JSONObject resultJson = new JSONObject();
        resultJson.put("listHomework", listHomework);
        return AjaxResult.success("查询成功", resultJson);
    }
    /**
     * 查询课后作业详情
     */
    @Operation(summary = "学生端我的页面查询课后作业详情")
    @GetMapping("/getHomeworkDetailInfo")
    public AjaxResult getHomeworkDetailInfo(@NotBlank(message = "课后作业id不能为空") String id)
    {
        EwcHomeworkAnalysisVo homeworkAnalysisVo = ewcHomeworkService.getHomeworkDetailInfo(ThirdSessionHolder.getThirdSession().getId(),id);
        JSONObject resultJson = new JSONObject();
        resultJson.put("homeworkAnalysisVo", homeworkAnalysisVo);
        return AjaxResult.success("查询成功", resultJson);
    }

}
